package com.re.control;
import com.re.pojo.Card;
import com.re.pojo.Player;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;

public class Play {
    private List<Card> box = new ArrayList<>(54);
    public void start() {
        //1.准备 54 张牌
        prepare();
        //2.发牌
        publish();
        //3. 显示牌
        show();

    }
    Player a , b , c;
    private void publish(){
        a = new Player("张三");
        b = new Player("李四");
        c = new Player("王五");


        for (int i = 0; i < 54 ; i++) {
            int randPos = new Random().nextInt(box.size()); //1.  0-53
            Card now= box.remove(randPos);

            int re = i % 3;
            switch(re){
                case 0 :
                    a.receiveCard(now);
                    break;
                case 1 :
                    b.receiveCard(now);
                    break;
                default:
                    c.receiveCard(now);

            }


        }
    }
    private void show(){
        a.showCards();
        b.showCards();
        c.showCards();

    }
    public void prepare() {
        for (int i = 1; i < 14; i++) {
            int size=i;
            String str_num = String.valueOf(i);
            switch(i){
                case 1:
                    size = 15;
                    str_num="A";
                    break;
                case 2:
                    size = 16;
                    break;
                case 11:
                    str_num="J";
                    break;
                case 12:
                    str_num="Q";
                    break;
                case 13:
                    str_num="K";
                    break;
            }
            Card c1=getCard("♠ ",str_num,size);
            Card c2=getCard("♥",str_num,size);
            Card c3=getCard("♦",str_num,size);
            Card c4=getCard("♣",str_num,size);
            box.add(c1);
            box.add(c2);
            box.add(c3);
            box.add(c4);

        }
        box.add(getCard("joker", "", 88));
        box.add(getCard("JOKER", "", 88));
    }

    private Card getCard(String pattern, String str_num, Integer t_num){
        Card card = new Card();
        card.setPattern(pattern);
        card.setStr_num(str_num);
        card.setT_num(t_num);
        return card;
    }

}